package com.nf.service;

import com.nf.model.Student;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class Test01 {
    public static void main(String[] args) {
        Configuration configuration=new Configuration().configure(); // 实例化配置文件
        SessionFactory sessionFactory=configuration.buildSessionFactory(); // 获取Session工厂
        Session session=sessionFactory.openSession(); // 生成一个session
        session.beginTransaction(); // 开启事务

        Student s=new Student();
        s.setName("张三");
        session.save(s);

        session.getTransaction().commit(); // 提交事务
        session.close(); // 关闭session
        sessionFactory.close(); // 关闭session工厂
    }
}
